//
//  SEGTemplateManagerModel.m
//  Uhomebk
//
//  Created by mac on 2017/9/20.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "SEGTemplateManagerModel.h"

@implementation SEGTemplateManagerModel
- (instancetype)initWithDictionary:(NSDictionary*)dictionary
{
    self = [super init];
    if (self) {
        _attrInstId=@"";
        _seq=@"";
        _disGroupid=@"";
        _attrCode=@"";
        _widgetType=@"";
        _contentLengthLimit=@"";
        _title=@"";
        _markedWords=@"";
        _expressCode=@"";
        _attrValueType=@"";
        _readable=@"";
        _writable=@"";
        _required=@"";
        _attrValue=@"";
        _Data_init=@"";//initData
        [self setValuesForKeysWithDictionary:dictionary];
        
    }
    return self;
}

+ (instancetype)initWithDictionary:(NSDictionary*)dictionary
{
    return [[self alloc] initWithDictionary:dictionary];
}

- (void)setValue:(id)value forUndefinedKey:(NSString*)key
{//注意此方法
    
}

-(void)setValue:(id)value forKey:(NSString *)key
{
    if ([key isEqualToString:@"initData"]) {
        _Data_init = [SEGUtils ValueToString:value];
        return;
    }
    if ([key isEqualToString:@"attrValue"]) {
        _attrValue = [SEGUtils ValueToString:value];
        return;
    }
    [super setValue:value forKey:key];
}

-(void)setAttrInstId:(NSString *)attrInstId
{
    _attrInstId = [SEGUtils ValueToString:attrInstId];
}

-(void)setSeq:(NSString *)seq
{
    _seq = [SEGUtils ValueToString:seq];
}

-(void)setDisGroupid:(NSString *)disGroupid
{
    _disGroupid = [SEGUtils ValueToString:disGroupid];
}

-(void)setAttrCode:(NSString *)attrCode
{
    _attrCode = [SEGUtils ValueToString:attrCode];
}

-(void)setWidgetType:(NSString *)widgetType
{
    _widgetType = [SEGUtils ValueToString:widgetType];
}

-(void)setContentLengthLimit:(NSString *)contentLengthLimit
{
    _contentLengthLimit = [SEGUtils ValueToString:contentLengthLimit];
}

-(void)setTitle:(NSString *)title
{
    _title = [SEGUtils ValueToString:title];
}

-(void)setMarkedWords:(NSString *)markedWords
{
    _markedWords = [SEGUtils ValueToString:markedWords];
}

-(void)setExpressCode:(NSString *)expressCode
{
    _expressCode = [SEGUtils ValueToString:expressCode];
}

-(void)setAttrValueType:(NSString *)attrValueType
{
    _attrValueType = [SEGUtils ValueToString:attrValueType];
}

-(void)setReadable:(NSString *)readable
{
    _readable = [SEGUtils ValueToString:readable];
}

-(void)setWritable:(NSString *)writable
{
    _writable = [SEGUtils ValueToString:writable];
}

-(void)setRequired:(NSString *)required
{
    _required = [SEGUtils ValueToString:required];
}

-(void)setAttrValue:(NSString *)attrValue
{
    _attrValue = [SEGUtils ValueToString:attrValue];
}

-(void)setData_init:(NSString *)Data_init
{
    _Data_init = [SEGUtils ValueToString:Data_init];
}
@end


@implementation SEGTemplateManagerModelArray
- (instancetype)initWithDictionary:(NSDictionary*)dictionary
{
    self = [super init];
    if (self) {
        _templateManagerModelArray = [[NSArray alloc] init];
        _message = @"";
        _code = @"";
        [self setValuesForKeysWithDictionary:dictionary];
    }
    return self;
}

+ (instancetype)initWithDictionary:(NSDictionary*)dictionary
{
    return [[self alloc] initWithDictionary:dictionary];
}

- (void)setValue:(id)value forUndefinedKey:(NSString*)key
{//注意此方法
    
}

-(void)setValue:(id)value forKey:(NSString *)key
{
    if ([key isEqualToString:@"data"]) {
        NSArray * arraydata;
        if ([value isKindOfClass:[NSArray class]]) {
            arraydata = (NSArray *)value;
        }

        if ( ! [value isKindOfClass:[NSArray class]]) {
            if ([value isKindOfClass:[NSDictionary class]]) {
                NSDictionary * dataDic = value;
                if ([dataDic.allKeys containsObject:@"formList"]) {
                    arraydata = dataDic[@"formList"];
                }else{
                    return;
                }
            }else{
               return;
            }
        }

        NSMutableArray * arraymutable = [[NSMutableArray alloc] init];
        for (id oneTemplate in arraydata) {
            SEGTemplateManagerModel * model = [[SEGTemplateManagerModel alloc] init];
            if ([oneTemplate isKindOfClass:[SEGTemplateManagerModel class]]) {
                model = (SEGTemplateManagerModel *)oneTemplate;
            }else{
                model = [SEGTemplateManagerModel initWithDictionary:(NSDictionary *)oneTemplate];
            }
            [arraymutable addObject:model];
        }
        _templateManagerModelArray = [[NSArray alloc] initWithArray:arraymutable];
        return;
    }
    [super setValue:value forKey:key];
}
@end
